package com.pfsbuilder;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.StringTokenizer;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.TreePath;
import javax.swing.undo.UndoManager;

import com.pfsbuilder.Dialogs.AutoGenerateDialog;
import com.pfsbuilder.Dialogs.BlockDialog;
import com.pfsbuilder.Dialogs.ImportDirectoryStatusDialog;
import com.pfsbuilder.Dialogs.JumpDialog;
import com.pfsbuilder.Dialogs.NewPFSDialog;
import com.pfsbuilder.Dialogs.OpenDialog;
import com.pfsbuilder.Dialogs.PWriteDialog;
import com.pfsbuilder.Dialogs.ReadDialog;
import com.pfsbuilder.Dialogs.SearchDialog;

public class MainFrame extends JFrame {
	JPanel contentPane;
	BorderLayout borderLayout1 = new BorderLayout();
	JToolBar toolBar1 = new JToolBar();
	JButton openToolBarButton = new JButton();
	JButton newToolBarButton = new JButton();
	JPanel mainPanel = new JPanel();
	BorderLayout borderLayout2 = new BorderLayout();
	JSplitPane splitPane1 = new JSplitPane();
	JScrollPane scrollPane1 = new JScrollPane();
	PFSTable pfsTable = new PFSTable();
	JSplitPane bottomSplitPane = new JSplitPane();
	JScrollPane treeScrollPane = new JScrollPane();
	JTree directoryTree = new JTree();
	JPopupMenu treePopupMenu = new JPopupMenu();
	JMenuItem addFileMenuItem = new JMenuItem();
	JPanel panel1 = new JPanel();
	JLabel fileLabel1 = new JLabel();
	JButton saveToolBarButton = new JButton();
	PFSTableModel pFSTableModel = new PFSTableModel();
	JMenuItem renameNodeMenuItem = new JMenuItem();
	JMenuItem deleteNodeMenuItem = new JMenuItem();
	JMenuItem deleteSubNodesMenuItem = new JMenuItem();
	JPopupMenu textPopupMenu = new JPopupMenu();
	JMenuItem cutMenuItem = new JMenuItem();
	JMenuItem copyMenuItem = new JMenuItem();
	JMenuItem pasteMenuItem = new JMenuItem();
	JMenuItem importMenuItem = new JMenuItem();

	ImageIcon mainIcon = new ImageIcon(MainFrame.class.getResource("images/AboutDialog/AboutDialog.png"));
	ImageIcon refreshJDirectoryTreeImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/PDirectoryTreeToolBarPanel/refresh.png"));
	ImageIcon newImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/new.png"));
	ImageIcon openImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/open.png"));
	ImageIcon saveImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/save.png"));
	ImageIcon saveDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/saveDisable.png"));
	ImageIcon aboutImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/about.png"));
	ImageIcon settingImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/setting.png"));
	ImageIcon settingDisabhleImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainToolbar/settingDisable.png"));

	ImageIcon editorSaveImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/save.png"));
	ImageIcon editorSaveDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/saveDisable.png"));
	ImageIcon editorRevertImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/revert.png"));
	ImageIcon editorRevertDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/revertDisable.png"));
	ImageIcon editorFillImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/fill.png"));
	ImageIcon editorUndoImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/undo.png"));
	ImageIcon editorUndoDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/undoDisable.png"));
	ImageIcon editorRedoImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/redo.png"));
	ImageIcon editorRedoDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/editor/redoDisable.png"));

	ImageIcon modeBlockImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/modeBlock.png"));
	ImageIcon modeByteImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/modeByte.png"));

	ImageIcon showFullHarddiskImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/showFullHarddisk.png"));
	ImageIcon showPartitionOnlyImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/showPartitionOnly.png"));

	ImageIcon searchImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/search.png"));
	ImageIcon searchDisableImage = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/searchDisable.png"));

	ImageIcon mainMenuFileIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainMenu/file.png"));
	ImageIcon mainMenuDirectoryIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/mainMenu/directory.png"));

	ImageIcon nextBlockIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/next.png"));
	ImageIcon previousBlockIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/previous.png"));
	ImageIcon jumoIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/upperToolbar/jump.png"));

	JMenuItem importDirectoryMenuItem = new JMenuItem();
	JMenuItem JMenuItem1 = new JMenuItem();
	JMenuItem addDirectoryMenuItem = new JMenuItem();
	JButton aboutToolBarButton = new JButton();
	PFSDefaultTreeCellRenderer pFSDefaultTreeCellRenderer = new PFSDefaultTreeCellRenderer();
	public PFSTreeModel pfsTreeModel;
	boolean stopFileLoading;
	HexTable_CellRenderer jHexTable_CellRenderer = new HexTable_CellRenderer();
	JPanel mainTablePanel = new JPanel();
	BorderLayout borderLayout6 = new BorderLayout();
	JPanel panel5 = new JPanel();
	JToolBar toolBar2 = new JToolBar();
	BorderLayout borderLayout7 = new BorderLayout();
	JToggleButton showHarddiskToolBarToggleButton = new JToggleButton();
	PFSTable_CellRenderer pFSTable_CellRenderer = new PFSTable_CellRenderer();
	JButton settingToolBarButton = new JButton();
	JToggleButton modeToolBarToggleButton = new JToggleButton();
	JButton searchToolBarButton = new JButton();
	JCheckBox decimalCheckBox = new JCheckBox();
	JCheckBox octalCheckBox = new JCheckBox();
	JCheckBox binaryCheckBox = new JCheckBox();
	JButton previousBlockToolBarButton = new JButton();
	JButton nextBlockToolBarButton = new JButton();
	JButton jumpToolBarButton = new JButton();
	JCheckBox hexCheckBox = new JCheckBox();
	JCheckBox characterCheckBox = new JCheckBox();
	UndoManager m_undoManager = new UndoManager();
	JumpDialog jJumpDialog = new JumpDialog(pfsTable);
	TreePath lastSelectedTreePath;
	private JComboBox themeComboBox;

	JPanel directoryTreePanel = new JPanel();
	BorderLayout borderLayout3 = new BorderLayout();
	JPanel directoryTreeToolBarPanel = new JPanel();
	JButton refreshDirectoryTreeButton = new JButton();
	JMenuItem autoGenerateMenuItem = new JMenuItem();
	JLabel pMainIconLabel = new JLabel();
	JScrollPane pScrollPane2 = new JScrollPane();

	public MainFrame() {
		try {
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			jbInit();
			splitPane1.setDividerLocation(200);
			bottomSplitPane.setDividerLocation(200);
		} catch (Exception exception) {
			exception.printStackTrace();
			contentPane = (JPanel) getContentPane();
			contentPane.setLayout(borderLayout1);
			contentPane.add(new JLabel(exception.toString()), java.awt.BorderLayout.CENTER);
			setSize(400, 300);
			CommonLib.centerDialog(this);
		}
	}

	private void jbInit() throws Exception {
		contentPane = (JPanel) getContentPane();
		contentPane.setLayout(borderLayout1);
		setTitle("PFSBuilder " + PropertyUtil.getProperty("version"));
		openToolBarButton.setText("Open");
		openToolBarButton.setIcon(new ImageIcon(MainFrame.class.getResource("/com/pfsbuilder/images/famfamfam/folder.png")));
		openToolBarButton.setVerticalTextPosition(SwingConstants.BOTTOM);
		openToolBarButton.setHorizontalTextPosition(SwingConstants.CENTER);
		openToolBarButton.addActionListener(new JMainFrame_pOpenToolBarButton_actionAdapter(this));
		newToolBarButton.setText("New");
		newToolBarButton.setIcon(new ImageIcon(MainFrame.class.getResource("/com/pfsbuilder/images/famfamfam/script.png")));
		newToolBarButton.setVerticalTextPosition(SwingConstants.BOTTOM);
		newToolBarButton.setHorizontalTextPosition(SwingConstants.CENTER);
		newToolBarButton.addActionListener(new JMainFrame_pNewToolBarButton_actionAdapter(this));
		mainPanel.setLayout(borderLayout2);
		addFileMenuItem.setText("Add File");
		addFileMenuItem.addActionListener(new JMainFrame_pAddNodeMenuItem_actionAdapter(this));
		directoryTree.addMouseListener(new JMainFrame_jTree1_mouseAdapter(this));
		fileLabel1.setText("");
		saveToolBarButton.setText("Save");
		saveToolBarButton.setIcon(new ImageIcon(MainFrame.class.getResource("/com/pfsbuilder/images/famfamfam/disk.png")));
		saveToolBarButton.setVerticalTextPosition(SwingConstants.BOTTOM);
		saveToolBarButton.setHorizontalTextPosition(SwingConstants.CENTER);
		saveToolBarButton.setEnabled(false);
		saveToolBarButton.addActionListener(new JMainFrame_pSaveToolBarButton_actionAdapter(this));
		directoryTree.setBackground(Color.lightGray);
		directoryTree.setEnabled(false);
		directoryTree.addTreeExpansionListener(new JMainFrame_jTree1_treeExpansionAdapter(this));
		pfsTable.setBackground(Color.lightGray);
		pfsTable.getTableHeader().setReorderingAllowed(false);
		pfsTable.setEnabled(false);
		pfsTable.addMouseListener(new JMainFrame_pMainTable_mouseAdapter(this));
		scrollPane1.getViewport().setBackground(Color.lightGray);
		deleteNodeMenuItem.setText("Delete");
		deleteNodeMenuItem.addActionListener(new JMainFrame_pDeleteNodeMenuItem_actionAdapter(this));
		deleteSubNodesMenuItem.setText("Delete all sub nodes");
		deleteSubNodesMenuItem.addActionListener(new JMainFrame_pDeleteSubNodesMenuItem_actionAdapter(this));
		renameNodeMenuItem.addActionListener(new JMainFrame_pRenameNodeMenuItem_actionAdapter(this));
		renameNodeMenuItem.setText("Rename");
		cutMenuItem.setToolTipText("");
		cutMenuItem.setText("Cut");
		cutMenuItem.addActionListener(new JMainFrame_pCutMenuItem_actionAdapter(this));
		pasteMenuItem.setText("Paste");
		pasteMenuItem.addActionListener(new JMainFrame_pPasteMenuItem_actionAdapter(this));
		copyMenuItem.setText("Copy");
		copyMenuItem.addActionListener(new JMainFrame_pCopyMenuItem_actionAdapter(this));
		importMenuItem.setToolTipText("");
		importMenuItem.setText("Import");
		importMenuItem.addActionListener(new JMainFrame_pImportMenuItem_actionAdapter(this));
		importDirectoryMenuItem.setText("Import Directory");
		importDirectoryMenuItem.addActionListener(new JMainFrame_pImportMenuItem_actionAdapter(this));
		addDirectoryMenuItem.setText("Add Directory");
		addDirectoryMenuItem.addActionListener(new JMainFrame_jAddDirectoryMenuItem_actionAdapter(this));
		aboutToolBarButton.setText("About");
		aboutToolBarButton.setIcon(new ImageIcon(MainFrame.class.getResource("/com/pfsbuilder/images/famfamfam/award_star_silver_3.png")));
		aboutToolBarButton.setVerticalTextPosition(SwingConstants.BOTTOM);
		aboutToolBarButton.setHorizontalTextPosition(SwingConstants.CENTER);
		aboutToolBarButton.addActionListener(new JMainFrame_pAboutToolBarButton_actionAdapter(this));
		mainTablePanel.setLayout(borderLayout6);
		splitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
		panel5.setLayout(borderLayout7);
		showHarddiskToolBarToggleButton.setEnabled(false);
		showHarddiskToolBarToggleButton.setMaximumSize(new Dimension(45, 35));
		showHarddiskToolBarToggleButton.setMinimumSize(new Dimension(45, 35));
		showHarddiskToolBarToggleButton.setPreferredSize(new Dimension(45, 35));
		showHarddiskToolBarToggleButton.setIcon(showFullHarddiskImage);
		showHarddiskToolBarToggleButton.setSelectedIcon(showPartitionOnlyImage);
		showHarddiskToolBarToggleButton.addActionListener(new JMainFrame_pShowHarddiskToolBarToggleButton_actionAdapter(this));
		settingToolBarButton.setEnabled(false);
		settingToolBarButton.setToolTipText("");
		settingToolBarButton.setText("Setting");
		settingToolBarButton.setDisabledSelectedIcon(null);
		settingToolBarButton.setIcon(new ImageIcon(MainFrame.class.getResource("/com/pfsbuilder/images/famfamfam/wrench.png")));
		settingToolBarButton.setVerticalTextPosition(SwingConstants.BOTTOM);
		settingToolBarButton.setHorizontalTextPosition(SwingConstants.CENTER);
		settingToolBarButton.addActionListener(new JMainFrame_pSettingToolBarButton_actionAdapter(this));
		modeToolBarToggleButton.setIcon(modeByteImage);
		modeToolBarToggleButton.setSelectedIcon(modeBlockImage);
		modeToolBarToggleButton.addActionListener(new JMainFrame_pModeToolBarToggleButton_actionAdapter(this));
		searchToolBarButton.setMaximumSize(new Dimension(40, 35));
		searchToolBarButton.setMinimumSize(new Dimension(40, 35));
		searchToolBarButton.setPreferredSize(new Dimension(40, 35));
		searchToolBarButton.setIcon(searchImage);
		searchToolBarButton.addActionListener(new JMainFrame_pSearchToolBarButton_actionAdapter(this));
		decimalCheckBox.setEnabled(false);
		decimalCheckBox.setText("D");
		decimalCheckBox.addActionListener(new JMainFrame_pDecimalCheckBox_actionAdapter(this));
		octalCheckBox.setEnabled(false);
		octalCheckBox.setText("O");
		octalCheckBox.addActionListener(new JMainFrame_pOctalCheckBox_actionAdapter(this));
		binaryCheckBox.setEnabled(false);
		binaryCheckBox.setText("B");
		binaryCheckBox.addActionListener(new JMainFrame_pBinaryCheckBox_actionAdapter(this));
		previousBlockToolBarButton.setEnabled(false);
		previousBlockToolBarButton.setMaximumSize(new Dimension(40, 40));
		previousBlockToolBarButton.setMinimumSize(new Dimension(40, 40));
		previousBlockToolBarButton.setPreferredSize(new Dimension(40, 40));
		previousBlockToolBarButton.setIcon(previousBlockIcon);
		previousBlockToolBarButton.addActionListener(new JMainFrame_pPreviousBlockToolBarButton_actionAdapter(this));
		nextBlockToolBarButton.setEnabled(false);
		nextBlockToolBarButton.setMaximumSize(new Dimension(40, 40));
		nextBlockToolBarButton.setMinimumSize(new Dimension(40, 40));
		nextBlockToolBarButton.setPreferredSize(new Dimension(40, 40));
		nextBlockToolBarButton.setIcon(nextBlockIcon);
		nextBlockToolBarButton.addActionListener(new JMainFrame_pNextBlockToolBarButton_actionAdapter(this));
		jumpToolBarButton.setEnabled(false);
		jumpToolBarButton.setMaximumSize(new Dimension(40, 40));
		jumpToolBarButton.setMinimumSize(new Dimension(40, 40));
		jumpToolBarButton.setPreferredSize(new Dimension(40, 40));
		jumpToolBarButton.setIcon(jumoIcon);
		jumpToolBarButton.addActionListener(new JMainFrame_pJumpToolBarButton_actionAdapter(this));
		hexCheckBox.setText("H");
		hexCheckBox.setEnabled(false);
		hexCheckBox.setSelected(true);
		hexCheckBox.addActionListener(new JMainFrame_pHexCheckBox_actionAdapter(this));
		characterCheckBox.setEnabled(false);
		characterCheckBox.setText("C");
		characterCheckBox.addActionListener(new JMainFrame_pCharacterCheckBox_actionAdapter(this));
		directoryTreePanel.setLayout(borderLayout3);
		refreshDirectoryTreeButton.setEnabled(false);
		refreshDirectoryTreeButton.setPreferredSize(new Dimension(30, 30));
		refreshDirectoryTreeButton.setIcon(refreshJDirectoryTreeImage);
		// pRefreshDirectoryTreeButton.setIconZoom(true);
		refreshDirectoryTreeButton.addActionListener(new JMainFrame_pRefreshDirectoryTreeButton_actionAdapter(this));
		autoGenerateMenuItem.setText("Auto Generate");
		autoGenerateMenuItem.addActionListener(new JMainFrame_pAutoGenerateMenuItem_actionAdapter(this));
		// pMainIconLabel.setIcon(mainIcon);
		toolBar1.add(settingToolBarButton);
		toolBar1.add(newToolBarButton);
		toolBar1.add(openToolBarButton);
		toolBar1.add(saveToolBarButton);
		toolBar1.add(settingToolBarButton);
		toolBar1.add(aboutToolBarButton);
		{
			ComboBoxModel pThemeComboBoxModel = new DefaultComboBoxModel(new String[] { "swing", "classic", "blue" });
			themeComboBox = new JComboBox();
			toolBar1.add(themeComboBox);
			themeComboBox.setModel(pThemeComboBoxModel);
			themeComboBox.setMaximumSize(new java.awt.Dimension(100, 25));
			themeComboBox.setSelectedItem("Classic");
			themeComboBox.setVisible(false);
			themeComboBox.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					pThemeComboBoxActionPerformed(evt);
				}
			});
		}
		contentPane.add(mainPanel, java.awt.BorderLayout.CENTER);
		mainPanel.add(splitPane1, java.awt.BorderLayout.CENTER);
		treePopupMenu.add(addFileMenuItem);
		treePopupMenu.add(addDirectoryMenuItem);
		treePopupMenu.add(renameNodeMenuItem);
		treePopupMenu.add(deleteNodeMenuItem);
		treePopupMenu.add(deleteSubNodesMenuItem);
		treePopupMenu.addSeparator();
		treePopupMenu.add(importDirectoryMenuItem);
		treePopupMenu.add(autoGenerateMenuItem);
		mainPanel.add(toolBar1, java.awt.BorderLayout.NORTH);
		mainPanel.add(panel1, java.awt.BorderLayout.SOUTH);
		panel1.add(fileLabel1);
		textPopupMenu.add(cutMenuItem);
		textPopupMenu.add(copyMenuItem);
		textPopupMenu.add(pasteMenuItem);
		textPopupMenu.addSeparator();
		textPopupMenu.add(importMenuItem);
		splitPane1.add(mainTablePanel, JSplitPane.TOP);
		scrollPane1.setViewportView(pfsTable);
		splitPane1.add(bottomSplitPane, JSplitPane.BOTTOM);
		mainTablePanel.add(scrollPane1, java.awt.BorderLayout.CENTER);
		mainTablePanel.add(panel5, java.awt.BorderLayout.NORTH);
		panel5.add(toolBar2, java.awt.BorderLayout.CENTER);
		toolBar2.add(modeToolBarToggleButton);
		toolBar2.add(showHarddiskToolBarToggleButton);
		toolBar2.add(searchToolBarButton);
		toolBar2.add(hexCheckBox);
		toolBar2.add(decimalCheckBox);
		toolBar2.add(octalCheckBox);
		toolBar2.add(binaryCheckBox);
		toolBar2.add(characterCheckBox);
		toolBar2.add(previousBlockToolBarButton);
		toolBar2.add(nextBlockToolBarButton);
		toolBar2.add(jumpToolBarButton);
		directoryTreePanel.add(treeScrollPane, java.awt.BorderLayout.CENTER);
		directoryTreePanel.add(directoryTreeToolBarPanel, java.awt.BorderLayout.NORTH);
		directoryTreeToolBarPanel.add(refreshDirectoryTreeButton);
		treeScrollPane.setViewportView(directoryTree);

		bottomSplitPane.add(pScrollPane2, JSplitPane.RIGHT);
		bottomSplitPane.add(directoryTreePanel, JSplitPane.LEFT);
		pScrollPane2.setViewportView(pMainIconLabel);
		pfsTable.setModel(pFSTableModel);
		directoryTree.setRowHeight(25);
		directoryTree.setShowsRootHandles(true);
		directoryTree.setCellRenderer(pFSDefaultTreeCellRenderer);
		directoryTree.setModel(null);
		enableEditorToolbarButtons(false);
		for (int x = 0; x < pfsTable.getColumnCount(); x++) {
			pfsTable.getColumnModel().getColumn(x).setCellRenderer(pFSTable_CellRenderer);
		}

		pfsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		pfsTable.setColumnSelectionAllowed(true);

		enableUpperToolBar(false);

		setSize(600, 600);
		CommonLib.centerDialog(this);
	}

	public void pNewToolBarButton_actionPerformed(ActionEvent e) {
		NewPFSDialog newPFSDialog = new NewPFSDialog(this, "New PFS", true, true);
		newPFSDialog.setVisible(true);
		if (newPFSDialog.isCancel() == false) {
			if (updateVariables(newPFSDialog)) {
				directoryTree.setBackground(Color.white);
				pfsTable.setBackground(Color.white);
				scrollPane1.getViewport().setBackground(Color.white);
				pfsTreeModel = new PFSTreeModel(PFSSettingConstants.tempDirectory);
				pFSTableModel.setValue(null);
				directoryTree.setModel(pfsTreeModel);

				saveToolBarButton.setEnabled(true);
				pfsTable.setEnabled(false);
				settingToolBarButton.setEnabled(true);
				directoryTree.setEnabled(true);
				refreshDirectoryTreeButton.setEnabled(true);
				enableUpperToolBar(false);

				initINIFile();
			}
		}
	}

	private void initINIFile() {
		PIni ini = new PIni("Setting.ini");
		// ini.removeProperty("Last opened project file","path");
		ini.setStringProperty("Last opened project file", "path", System.getProperty("user.dir"), null);
		// ini.removeProperty("Last opened PFS image","path");
		ini.setStringProperty("Last opened PFS image", "path", System.getProperty("user.dir"), null);
		ini.save();

		new File(PFSSettingConstants.projectFile).delete();
	}

	private void enableUpperToolBar(boolean b) {
		showHarddiskToolBarToggleButton.setEnabled(b);
		modeToolBarToggleButton.setEnabled(b);
		searchToolBarButton.setEnabled(b);
		hexCheckBox.setEnabled(b);
		decimalCheckBox.setEnabled(b);
		octalCheckBox.setEnabled(b);
		binaryCheckBox.setEnabled(b);
		characterCheckBox.setEnabled(b);
		previousBlockToolBarButton.setEnabled(b);
		nextBlockToolBarButton.setEnabled(b);
		jumpToolBarButton.setEnabled(b);
	}

	private boolean updateVariables(NewPFSDialog newPFSDialog) {
		if (newPFSDialog.getOutputFilename() != null) {
			PFSSettingConstants.filename = newPFSDialog.getOutputFilename();
			PFSSettingConstants.projectFile = newPFSDialog.getProjectFile();
			if (!new File(PFSSettingConstants.projectFile).getParentFile().exists()) {
				if (!new File(PFSSettingConstants.projectFile).getParentFile().mkdirs()) {
					JOptionPane.showMessageDialog(this, PFSSettingConstants.projectFile + " cannot be created !!!", "Error", JOptionPane.ERROR_MESSAGE);
					return false;
				}
			}

			PFSSettingConstants.partitionOffset = Long.parseLong(newPFSDialog.getPartitionOffset());
			PFSSettingConstants.partitionName = newPFSDialog.getPartitionName();
			PFSSettingConstants.partitionSize = Long.parseLong(newPFSDialog.getPartitionSize());
			StringTokenizer stk = new StringTokenizer(newPFSDialog.getBlockSize(), " ");
			PFSSettingConstants.blockSize = Integer.parseInt(stk.nextToken()) * 1024;
			PFSSettingConstants.version = newPFSDialog.getVersion();
			PFSSettingConstants.C = newPFSDialog.getC();
			PFSSettingConstants.H = newPFSDialog.getH();
			PFSSettingConstants.S = newPFSDialog.getS();
			PFSSettingConstants.tempDirectory = newPFSDialog.getTempDirectory();
			if (!new File(PFSSettingConstants.tempDirectory).exists()) {
				if (!new File(PFSSettingConstants.tempDirectory).mkdirs()) {
					JOptionPane.showMessageDialog(this, PFSSettingConstants.tempDirectory + " cannot be created !!!", "Error", JOptionPane.ERROR_MESSAGE);

					return false;
				}
			}
			return true;
		} else {
			JOptionPane.showMessageDialog(this, "Output filename is null", "Error", JOptionPane.ERROR_MESSAGE);

			return false;
		}
	}

	public void jDirectoryTree_mouseClicked(MouseEvent e) {
		Component component = bottomSplitPane.getRightComponent();
		if (component.getClass() == PFSFilePropertyPanel.class) {
			PFSFilePropertyPanel pFSFilePropertyPanel = (PFSFilePropertyPanel) bottomSplitPane.getRightComponent();
			if (pFSFilePropertyPanel.shouldSave) {
				int returnValue = JOptionPane.showConfirmDialog(this, "Save file?", "Question", JOptionPane.YES_NO_CANCEL_OPTION);
				if (returnValue == JOptionPane.YES_OPTION) {
					pFSFilePropertyPanel.saveFile();
				} else if (returnValue == JOptionPane.CANCEL_OPTION) {
					directoryTree.setSelectionPath(lastSelectedTreePath);
					return;
				}
			}
		}

		if (directoryTree.isEnabled()) {
			TreePath selectedPath = directoryTree.getPathForLocation(e.getX(), e.getY());
			if (selectedPath != null) {
				if (SwingUtilities.isRightMouseButton(e)) {
					// right mouse click
					// updateTextToNode();

					// check is node selected
					boolean nodeSelected = false;
					TreePath selectedTreePaths[] = directoryTree.getSelectionPaths();
					if (selectedTreePaths != null) {
						for (int x = 0; x < selectedTreePaths.length; x++) {
							if (selectedTreePaths[x] == selectedPath) {
								nodeSelected = true;
								break;
							}
						}
					}
					// end check is node selected
					boolean isRoot = (pfsTreeModel.getRoot() == selectedPath.getLastPathComponent()) ? true : false;
					if (!nodeSelected || isRoot) {
						directoryTree.setSelectionPath(selectedPath);
					}
					if (isRoot) {
						this.deleteNodeMenuItem.setEnabled(false);
						this.renameNodeMenuItem.setEnabled(false);
					} else {
						this.deleteNodeMenuItem.setEnabled(true);
						this.renameNodeMenuItem.setEnabled(true);
					}
					if (((File) selectedPath.getLastPathComponent()).isFile()) {
						this.addDirectoryMenuItem.setEnabled(false);
						this.addFileMenuItem.setEnabled(false);
					} else {
						this.addDirectoryMenuItem.setEnabled(true);
						this.addFileMenuItem.setEnabled(true);
					}
					treePopupMenu.show(e.getComponent(), e.getX(), e.getY());
				} else {
					// left mouse click
					stopFileLoading = false;
					if (directoryTree.getSelectionPath() != null) {
						File selectedFile = (File) directoryTree.getSelectionPath().getLastPathComponent();
						// if (selectedFile.toString().equals(
						// PFSSettingConstants.tempDirectory)) {
						// } else {
						enableEditorToolbarButtons(selectedFile.isFile());
						if (selectedFile.isFile()) {
							PFSFilePropertyPanel pFSFilePropertyPanel = new PFSFilePropertyPanel(this, PFSSettingConstants.projectFile, selectedFile);
							addComponentToBottomSplitPane(pFSFilePropertyPanel);
							if (selectedFile.length() <= 1024 * 1024 * 10) {
								pFSFilePropertyPanel.loadFile();
							} else {
								JOptionPane.showMessageDialog(this, "Unable to open >10MB file", "Warning", JOptionPane.WARNING_MESSAGE);
							}
						} else {
							PFSDirectoryPropertyPanel pFSDirectoryPropertyPanel = new PFSDirectoryPropertyPanel(PFSSettingConstants.projectFile, selectedFile.getAbsolutePath());
							addComponentToBottomSplitPane(pFSDirectoryPropertyPanel);
						}
						// }
					}
				}
			}
		}
		lastSelectedTreePath = directoryTree.getSelectionPath();
	}

	private void addComponentToBottomSplitPane(Component component) {
		int dividerLocation = bottomSplitPane.getDividerLocation();
		bottomSplitPane.add(component, JSplitPane.RIGHT);
		bottomSplitPane.setDividerLocation(dividerLocation);
	}

	private void enableEditorToolbarButtons(boolean b) {
	}

	// public void jEditorPane1_keyReleased(KeyEvent e) {
	// TreePath selectedPath = jDirectoryTree.getSelectionPath();
	// if (selectedPath != null) {
	// pFileLabel1.setText("Length of file : " +
	// .length());
	//
	// shouldSave = true;
	// }
	// }

	public void pSaveToolBarButton_actionPerformed(ActionEvent e) {
		PWriteDialog pWriteDialog = new PWriteDialog(this, "Writing...", true);
		pWriteDialog.setVisible(true);

		PFSImageConstants.filename = PFSSettingConstants.filename;
		PFSImageConstants.blockSize = PFSSettingConstants.blockSize;
		PFSImageConstants.partitionSize = PFSSettingConstants.partitionSize;
		PFSImageConstants.partitionOffset = PFSSettingConstants.partitionOffset;

		pFSTableModel.setValue(PFSImageConstants.filename);
		pfsTable.setEnabled(true);
		enableUpperToolBar(true);
	}

	public Object showInputDialog(Component parentComponent, String title, Object message, String initialSelectionValue) throws HeadlessException {
		JOptionPane pane = new JOptionPane("rename file", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
		pane.setWantsInput(true);
		pane.setInitialSelectionValue(initialSelectionValue);
		pane.setComponentOrientation(parentComponent.getComponentOrientation());
		JDialog dialog = pane.createDialog(parentComponent, "?");
		pane.selectInitialValue();
		dialog.setVisible(true);
		Object value = pane.getInputValue();
		if (value == "uninitializedValue") {
			return null;
		}
		return value;
	}

	public void pRenameNodeMenuItem_actionPerformed(ActionEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			Object str = showInputDialog(this, "?", "Rename file : ", ((File) selectedPath.getLastPathComponent()).getName());
			if (str != null) {
				File node = (File) selectedPath.getLastPathComponent();
				File newFile = new File(node.getParentFile().getAbsolutePath() + File.separator + str);

				node.renameTo(newFile);

				if (bottomSplitPane.getClass().equals(PFSFilePropertyPanel.class)) {
					PFSFilePropertyPanel pFSFilePropertyPanel = (PFSFilePropertyPanel) bottomSplitPane.getRightComponent();
					pFSFilePropertyPanel.renameFileTo(newFile);

					pfsTreeModel.fireTreeStructureChanged(node);
				}
				this.pRefreshDirectoryTreeButton_actionPerformed(null);
			}
		}
	}

	public void pDeleteNodeMenuItem_actionPerformed(ActionEvent e) {
		int str = JOptionPane.showConfirmDialog(this, "Sure to delete : " + ((File) directoryTree.getLastSelectedPathComponent()).getName(), "?", JOptionPane.WARNING_MESSAGE);
		if (str == JOptionPane.YES_OPTION) {
			TreePath selectedTreePaths[] = directoryTree.getSelectionPaths();
			for (int x = 0; x < selectedTreePaths.length; x++) {
				File file = (File) selectedTreePaths[x].getLastPathComponent();
				if (file.isFile()) {
					if (!file.delete()) {
						JOptionPane.showMessageDialog(this, "Fail to delete file : " + file.getAbsolutePath(), "Error", JOptionPane.ERROR_MESSAGE);
					}
				} else {
					CommonLib.deleteDirectory(file);
				}
			}
			this.pRefreshDirectoryTreeButton_actionPerformed(null);
		}
	}

	public void pDeleteSubNodesMenuItem_actionPerformed(ActionEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			if (selectedPath == null) { // Path not found because
				return; // right click does not occur on a node or a leaf
			}

			File node = (File) directoryTree.getLastSelectedPathComponent();
			File nodes[] = node.listFiles();
			for (int x = 0; x < nodes.length; x++) {
				if (nodes[x].isDirectory()) {
					CommonLib.deleteDirectory(nodes[x]);
				} else {
					nodes[x].delete();
				}
			}
			pfsTreeModel.fireTreeStructureChanged(node);
		}
	}

	public void jEditorPane1_mouseClicked(MouseEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			if (SwingUtilities.isRightMouseButton(e)) {
				textPopupMenu.show(e.getComponent(), e.getX(), e.getY());
			} else {
				// if (selectedPath != null) {
				// File node = (File) selectedPath.
				// getLastPathComponent();
				// node.caretPosition = jEditorPane.getCaretPosition();
				// }
			}
		}
	}

	public void pCutMenuItem_actionPerformed(ActionEvent e) {
	}

	public void pCopyMenuItem_actionPerformed(ActionEvent e) {
	}

	public void pPasteMenuItem_actionPerformed(ActionEvent e) {
	}

	public void pImportMenuItem_actionPerformed(ActionEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			JFileChooser pFileChooserDialog = new JFileChooser();
			pFileChooserDialog.setMultiSelectionEnabled(true);
			pFileChooserDialog.setSize(500, 500);
			CommonLib.centerDialog(pFileChooserDialog);
			pFileChooserDialog.setFileSelectionMode(pFileChooserDialog.DIRECTORIES_ONLY);
			pFileChooserDialog.setAcceptAllFileFilterUsed(false);

			if (pFileChooserDialog.showOpenDialog(this) == pFileChooserDialog.APPROVE_OPTION) {
				File files[] = pFileChooserDialog.getSelectedFiles();

				if (files.length > 0) {
					File node = (File) selectedPath.getLastPathComponent();
					ImportDirectoryStatusDialog jImportDirectoryStatusDialog = new ImportDirectoryStatusDialog(this, "Import directory", true, node, files);
					CommonLib.centerDialog(jImportDirectoryStatusDialog);
					jImportDirectoryStatusDialog.setVisible(true);
					pfsTreeModel.fireTreeStructureChanged(node);
				}
			}
		}
	}

	public void pAddFileMenuItem_actionPerformed(ActionEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			String str = JOptionPane.showInputDialog(this, "Input filename", "Add file", JOptionPane.QUESTION_MESSAGE);

			if (str == null) {
				return;
			} else {
				try {
					File node = (File) selectedPath.getLastPathComponent();
					File newFile = new File(node + File.separator + str);
					if (!newFile.createNewFile()) {
						JOptionPane.showMessageDialog(this, "Cannot create File", "Error", JOptionPane.ERROR_MESSAGE);
						return;
					}

					pfsTreeModel.fireTreeStructureChanged(node);
					directoryTree.setSelectionPath(pfsTreeModel.getTreePath(newFile));
					lastSelectedTreePath = directoryTree.getSelectionPath();
					PFSFilePropertyPanel pFSFilePropertyPanel = new PFSFilePropertyPanel(this, PFSSettingConstants.projectFile, newFile);
					addComponentToBottomSplitPane(pFSFilePropertyPanel);
					this.enableEditorToolbarButtons(true);
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(this, "Cannot create File", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		}
	}

	public void pAddDirectoryMenuItem_actionPerformed(ActionEvent e) {
		TreePath selectedPath = directoryTree.getSelectionPath();
		if (selectedPath != null) {
			String str = JOptionPane.showInputDialog(this, "Input directory name", "Add directory", JOptionPane.QUESTION_MESSAGE);

			if (str == null) {
				return;
			} else {
				try {
					File node = (File) selectedPath.getLastPathComponent();
					File newDirectory = new File(node + File.separator + str);
					if (!newDirectory.mkdir()) {
						JOptionPane.showMessageDialog(this, "Cannot create directory", "Error", JOptionPane.ERROR_MESSAGE);
						return;
					}
					pfsTreeModel.fireTreeStructureChanged(node);
					directoryTree.setSelectionPath(pfsTreeModel.getTreePath(newDirectory));
					lastSelectedTreePath = directoryTree.getSelectionPath();

					PFSDirectoryPropertyPanel pFSDirectoryPropertyPanel = new PFSDirectoryPropertyPanel(PFSSettingConstants.projectFile, newDirectory.getAbsolutePath());
					addComponentToBottomSplitPane(pFSDirectoryPropertyPanel);
					this.enableEditorToolbarButtons(true);
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(this, "Cannot create directory", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		}
	}

	public void pAboutToolBarButton_actionPerformed(ActionEvent e) {
		new AboutBox(this).setVisible(true);
	}

	public void jTree1_treeExpanded(TreeExpansionEvent event) {
		// TreePath selectedPath = jTree1.getSelectionPath();
		// if (selectedPath != null) {
		// PFSDefaultMutableTreeNode node = (PFSDefaultMutableTreeNode)
		// selectedPath.
		// getLastPathComponent();
		// node.removeAllChildren();
		// Object objs[] = selectedPath.getPath();
		// String filepath = "temp" + File.separator;
		// for (int x = 1; x < objs.length; x++) {
		// filepath += objs[x].toString() + File.separator;
		// }
		// if (new File(filepath).isDirectory()) {
		// for (File file : new File(filepath).listFiles()) {
		// PFSDefaultMutableTreeNode addnode = new
		// PFSDefaultMutableTreeNode(file,
		// file.isFile());
		// node.add(addnode);
		// }
		// }
		// pFSTreeModel.fireTreeStructureChanged(node);
		// }
	}

	public void jTree1_treeCollapsed(TreeExpansionEvent event) {
		// PFSDefaultMutableTreeNode node = (PFSDefaultMutableTreeNode)
		// selectedPath.
		// getLastPathComponent();
	}

	public void pCancelFileLoadingButton_actionPerformed(ActionEvent e) {
		stopFileLoading = true;
	}

	// public void pSaveEditorToolBarButton_actionPerformed(ActionEvent e) {
	// try {
	// if (selectedFile != null) {
	// BufferedWriter bw = new BufferedWriter(new FileWriter(selectedFile));
	// bw.write();
	// bw.close();
	// }
	// } catch (Exception ex) {
	// ex.printStackTrace();
	// }
	// }

	public void pMainTable_mouseClicked(MouseEvent e) {
		if (e.getClickCount() == 2) {
			if (pFSTableModel.getMode() == 1) {
				long fileOffset = pfsTable.getSelectedRow() * (pfsTable.getColumnCount() - 1) * PFSImageConstants.blockSize;
				if (fileOffset >= PFSImageConstants.partitionOffset - pFSTableModel.getShowOffset()
						&& fileOffset <= PFSImageConstants.partitionSize + PFSImageConstants.partitionOffset - pFSTableModel.getShowOffset()) {
					long blockNo = pfsTable.getSelectedRow() * (pfsTable.getColumnCount() - 1) + pfsTable.getSelectedColumn() - 2;
					new BlockDialog(this, String.valueOf(blockNo), (byte[]) pfsTable.getValueAt(pfsTable.getSelectedRow(), pfsTable.getSelectedColumn())).setVisible(true);
				}
			}
		}
	}

	public void pSettingToolBarButton_actionPerformed(ActionEvent e) {
		NewPFSDialog jNewPFSDialog = new NewPFSDialog(this, "Change PFS", true, false);
		jNewPFSDialog.setVisible(true);
		if (jNewPFSDialog.isCancel() == false && jNewPFSDialog.getOutputFilename() != null && jNewPFSDialog.getProjectFile() != null) {
			// if (jNewPFSDialog.isCancel() == false &&
			// jNewPFSDialog.getOutputFilename() != null &&
			// jNewPFSDialog.getProjectFile() != null) {
			updateVariables(jNewPFSDialog);
		}
	}

	public void pOpenToolBarButton_actionPerformed(ActionEvent e) {
		OpenDialog pOpenDialog = new OpenDialog(this);
		pOpenDialog.setVisible(true);
		if (!pOpenDialog.isCancel) {
			try {
				if (new File(pOpenDialog.tempDirectoryLabel.getText()).exists()) {
					int returnValue = JOptionPane.showConfirmDialog(this, pOpenDialog.tempDirectoryLabel.getText() + " exist, remove it?", "Question", JOptionPane.YES_NO_OPTION);
					if (returnValue == JOptionPane.YES_OPTION) {
						CommonLib.deleteDirectory(pOpenDialog.tempDirectoryLabel.getText());
					}
				}
				new File(pOpenDialog.tempDirectoryLabel.getText()).mkdir();
				if (pOpenDialog.radioButton1.isSelected()) {
					String offsetText = pOpenDialog.partitionOffsetTextField.getText();
					try {
						PFSImageConstants.partitionOffset = Long.parseLong(offsetText);
					} catch (Exception ex) {
						PFSImageConstants.partitionOffset = CommonLib.convertFilesize(offsetText);
					}
				} else {
					String offsetText = pOpenDialog.offsetComboBox.getItemAt(pOpenDialog.offsetComboBox.getSelectedIndex()).toString();

					if (offsetText.indexOf(":") != -1) {
						offsetText = offsetText.substring(0, offsetText.indexOf(":"));
					}
					PFSImageConstants.partitionOffset = Long.parseLong(offsetText);
				}

				PFSImageConstants.filename = pOpenDialog.pfsFileLabel.getText();
				PFSSettingConstants.filename = PFSImageConstants.filename;

				PFSSettingConstants.partitionOffset = PFSImageConstants.partitionOffset;

				PFSImageConstants.partitionSize = new File(PFSImageConstants.filename).length() - PFSImageConstants.partitionOffset;
				PFSSettingConstants.partitionSize = PFSImageConstants.partitionSize;

				PFSSettingConstants.tempDirectory = pOpenDialog.tempDirectoryLabel.getText();
				PFSSettingConstants.projectFile = pOpenDialog.pProjectFileLabel.getText();

				ReadDialog pReadDialog = new ReadDialog(this, "Reading PFS...", true);
				pReadDialog.setVisible(true);
				// updateVariables(pReadDialog);

				directoryTree.setBackground(Color.white);
				pfsTreeModel = new PFSTreeModel(PFSSettingConstants.tempDirectory);
				directoryTree.setModel(pfsTreeModel);
				pFSTableModel.setValue(PFSImageConstants.filename);
				// pShowHarddiskToolBarToggleButton.setState(false);

				saveToolBarButton.setEnabled(true);
				pfsTable.setEnabled(true);
				directoryTree.setEnabled(true);
				settingToolBarButton.setEnabled(true);
				enableUpperToolBar(true);
				refreshDirectoryTreeButton.setEnabled(true);
			} catch (Exception ex) {
				ex.printStackTrace();
				if (com.pfsbuilder.Global.GUI) {
					new PExceptionDialog(ex, com.pfsbuilder.Global.sessionNumber).setVisible(true);
				}
			}
		}
	}

	public void pSearchToolBarButton_actionAdapter(ActionEvent e) {
		new SearchDialog(this, "Search", true).setVisible(true);
	}

	public void pModeToolBarToggleButton_actionPerformed(ActionEvent e) {
		try {
			int row = pfsTable.getSelectedRow();
			int column = pfsTable.getSelectedColumn();
			int columnCount = pfsTable.getColumnCount();

			if (pFSTableModel.getMode() == 0) {
				pFSTableModel.setMode(1);

				long offset = row * (columnCount - 1) + (column - 1);
				int blockNumber = (int) offset / PFSImageConstants.blockSize;
				int selectRowNumber = blockNumber / (columnCount - 1);
				int selectColumnNumber = blockNumber - (selectRowNumber * (columnCount - 1));
				if (selectRowNumber > 0 && selectRowNumber < pfsTable.getRowCount() && (selectColumnNumber + 1) > 0 && (selectColumnNumber + 1) < pfsTable.getColumnCount()) {
					pfsTable.selectAndVisibleRow(selectRowNumber, selectColumnNumber + 1);
				}
			} else if (pFSTableModel.getMode() == 1) {
				pFSTableModel.setMode(0);

				int blockNumber = (row * (columnCount - 1)) + column - 1;
				long offset = blockNumber * PFSImageConstants.blockSize;
				int selectRowNumber = (int) offset / (columnCount - 1);
				int selectColumnNumber = (int) offset - selectRowNumber * (columnCount - 1);
				if (selectRowNumber > 0 && selectRowNumber < pfsTable.getRowCount() && (selectColumnNumber + 1) > 0 && (selectColumnNumber + 1) < pfsTable.getColumnCount()) {
					pfsTable.selectAndVisibleRow(selectRowNumber, selectColumnNumber + 1);
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			if (com.pfsbuilder.Global.GUI) {
				new PExceptionDialog(ex, com.pfsbuilder.Global.sessionNumber).setVisible(true);
			}
		}
	}

	public void pShowHarddiskToolBarToggleButton_actionPerformed(ActionEvent e) {
		if (showHarddiskToolBarToggleButton.isSelected()) {
			// show partition only
			pFSTableModel.setShowOffset(PFSImageConstants.partitionOffset);
		} else {
			// show all harddisk image
			pFSTableModel.setShowOffset(0);
		}
	}

	public void pJumpToolBarButton_actionPerformed(ActionEvent e) {
		if (jJumpDialog.isVisible()) {
			jJumpDialog.toFront();
		} else {
			jJumpDialog.setVisible(true);
		}
	}

	public void pNextBlockToolBarButton_actionPerformed(ActionEvent e) {
		int columnCount = pfsTable.getColumnCount();
		int rowCount = pfsTable.getRowCount();
		int selectedRow = pfsTable.getSelectedRow();
		int selectedColumn = pfsTable.getSelectedColumn();

		if (selectedRow == -1) {
			pfsTable.setRowSelectionInterval(0, 0);
			pfsTable.setColumnSelectionInterval(1, 1);
			selectedRow = 0;
			selectedColumn = 1;
		}

		if (pFSTableModel.getMode() == 0) {
			int newRowNumber = selectedRow + PFSImageConstants.blockSize / (columnCount - 1);
			if (newRowNumber < pfsTable.getRowCount()) {
				pfsTable.setRowSelectionInterval(newRowNumber, newRowNumber);
				pfsTable.selectAndVisibleRow(newRowNumber, selectedColumn);
			}
		} else if (pFSTableModel.getMode() == 1) {
			if (selectedColumn != columnCount - 1) {
				pfsTable.setColumnSelectionInterval(selectedColumn + 1, selectedColumn + 1);
			} else {
				pfsTable.setColumnSelectionInterval(1, 1);
				pfsTable.setRowSelectionInterval(selectedRow + 1, selectedRow + 1);
				pfsTable.selectAndVisibleRow(selectedRow + 1, selectedColumn);
			}
		}
	}

	public void pPreviousBlockToolBarButton_actionPerformed(ActionEvent e) {
		int columnCount = pfsTable.getColumnCount();
		int rowCount = pfsTable.getRowCount();
		int selectedRow = pfsTable.getSelectedRow();
		int selectedColumn = pfsTable.getSelectedColumn();

		if (pFSTableModel.getMode() == 0) {
			int newRowNumber = selectedRow - PFSImageConstants.blockSize / (columnCount - 1);
			if (newRowNumber < 0 || newRowNumber >= rowCount) {
				return;
			}
			pfsTable.setRowSelectionInterval(newRowNumber, newRowNumber);
			scrollPane1.getViewport().setViewPosition(new Point(0, pfsTable.getMaximumSize().height));
		} else if (pFSTableModel.getMode() == 1) {
			if (selectedColumn != 1) {
				pfsTable.setColumnSelectionInterval(selectedColumn - 1, selectedColumn - 1);
			} else {
				pfsTable.setColumnSelectionInterval(columnCount - 1, columnCount - 1);
				pfsTable.setRowSelectionInterval(selectedRow - 1, selectedRow - 1);
			}
		}
	}

	public void pHexCheckBox_actionPerformed(ActionEvent e) {
		this.pFSTableModel.setShowHex(hexCheckBox.isSelected());
	}

	public void pDecimalCheckBox_actionPerformed(ActionEvent e) {
		this.pFSTableModel.setShowDecimal(decimalCheckBox.isSelected());
	}

	public void pOctalCheckBox_actionPerformed(ActionEvent e) {
		this.pFSTableModel.setShowOctal(octalCheckBox.isSelected());
	}

	public void pBinaryCheckBox_actionPerformed(ActionEvent e) {
		this.pFSTableModel.setShowBinary(binaryCheckBox.isSelected());
	}

	public void pCharacterCheckBox_actionPerformed(ActionEvent e) {
		this.pFSTableModel.setShowCharacter(characterCheckBox.isSelected());
	}

	public void pRefreshDirectoryTreeButton_actionPerformed(ActionEvent e) {
		TreePath lastSelectedTreePath = directoryTree.getSelectionPath();
		pfsTreeModel = new PFSTreeModel(PFSSettingConstants.tempDirectory);
		directoryTree.setModel(pfsTreeModel);
		directoryTree.setSelectionPath(lastSelectedTreePath);
	}

	public void pAutoGenerateMenuItem_actionPerformed(ActionEvent e) {
		new AutoGenerateDialog(this, this.directoryTree, PFSSettingConstants.projectFile).setVisible(true);
	}

	private void pThemeComboBoxActionPerformed(ActionEvent evt) {
		System.out.println(themeComboBox.getSelectedItem().toString());
		// PetersoftJavaStyle.setStyle(pThemeComboBox.getSelectedItem().toString());
		this.repaint();
	}
}

class JMainFrame_pAutoGenerateMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pAutoGenerateMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pAutoGenerateMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pRefreshDirectoryTreeButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pRefreshDirectoryTreeButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pRefreshDirectoryTreeButton_actionPerformed(e);
	}
}

class JMainFrame_pCharacterCheckBox_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pCharacterCheckBox_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pCharacterCheckBox_actionPerformed(e);
	}
}

class JMainFrame_pBinaryCheckBox_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pBinaryCheckBox_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pBinaryCheckBox_actionPerformed(e);
	}
}

class JMainFrame_pOctalCheckBox_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pOctalCheckBox_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pOctalCheckBox_actionPerformed(e);
	}
}

class JMainFrame_pDecimalCheckBox_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pDecimalCheckBox_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pDecimalCheckBox_actionPerformed(e);
	}
}

class JMainFrame_pPreviousBlockToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pPreviousBlockToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pPreviousBlockToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pNextBlockToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pNextBlockToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pNextBlockToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pJumpToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pJumpToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pJumpToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pHexCheckBox_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pHexCheckBox_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pHexCheckBox_actionPerformed(e);
	}
}

class JMainFrame_pShowHarddiskToolBarToggleButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pShowHarddiskToolBarToggleButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pShowHarddiskToolBarToggleButton_actionPerformed(e);
	}
}

class JMainFrame_pModeToolBarToggleButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pModeToolBarToggleButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pModeToolBarToggleButton_actionPerformed(e);
	}
}

class JMainFrame_pOpenToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pOpenToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pOpenToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pSettingToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pSettingToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pSettingToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pMainTable_mouseAdapter extends MouseAdapter {
	private MainFrame adaptee;

	JMainFrame_pMainTable_mouseAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void mouseClicked(MouseEvent e) {
		adaptee.pMainTable_mouseClicked(e);
	}
}

class JMainFrame_pAboutToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pAboutToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pAboutToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_jAddDirectoryMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_jAddDirectoryMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pAddDirectoryMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pImportMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pImportMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pImportMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pPasteMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pPasteMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pPasteMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pCopyMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pCopyMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pCopyMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pCutMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pCutMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pCutMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pDeleteSubNodesMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pDeleteSubNodesMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pDeleteSubNodesMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pRenameNodeMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pRenameNodeMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pRenameNodeMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pDeleteNodeMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pDeleteNodeMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pDeleteNodeMenuItem_actionPerformed(e);
	}
}

class JMainFrame_pSaveToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pSaveToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pSaveToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pAddNodeMenuItem_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pAddNodeMenuItem_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {

		adaptee.pAddFileMenuItem_actionPerformed(e);
	}
}

class JMainFrame_jTree1_mouseAdapter extends MouseAdapter {
	private MainFrame adaptee;

	JMainFrame_jTree1_mouseAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void mouseClicked(MouseEvent e) {
		adaptee.jDirectoryTree_mouseClicked(e);
	}
}

class JMainFrame_jTree1_treeExpansionAdapter implements TreeExpansionListener {
	private MainFrame adaptee;

	JMainFrame_jTree1_treeExpansionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void treeExpanded(TreeExpansionEvent event) {
		adaptee.jTree1_treeExpanded(event);
	}

	public void treeCollapsed(TreeExpansionEvent event) {
		adaptee.jTree1_treeCollapsed(event);
	}
}

class JMainFrame_pNewToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pNewToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pNewToolBarButton_actionPerformed(e);
	}
}

class JMainFrame_pSearchToolBarButton_actionAdapter implements ActionListener {
	private MainFrame adaptee;

	JMainFrame_pSearchToolBarButton_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.pSearchToolBarButton_actionAdapter(e);
	}
}
